#import "Order.h"

@implementation Order

@synthesize orderId;
@synthesize createTime;
@synthesize updateTime;
@synthesize desknum;
@synthesize totalCost;
@synthesize menus;

-(id)init{
	[super init];
	orderId=nil;
	updateTime=nil;
	NSDate *now=[NSDate date];
	createTime=[NSNumber numberWithUnsignedLongLong:((long long)([now timeIntervalSince1970]*1000))];
	return self;
}

-(id)proxyForJson{
	return [NSDictionary dictionaryWithObjectsAndKeys:
			orderId==nil?[NSNull null]:orderId,@"id",
			createTime,@"createTime",
			updateTime==nil?[NSNull null]:updateTime,@"updateTime",
			desknum,@"desknum",
			totalCost==nil?[NSNull null]:totalCost,@"totalCost",
			menus==nil?[NSNull null]:menus,@"menus",
		nil];
}

-(id)dealloc{
	[orderId release];
	[createTime release];
	[updateTime release];
	[desknum release];
	[totalCost release];
	[menus release];
	[super dealloc];
}

+(Order*)fromJsonObj:(id)obj{
	Order* ret=[Order new];
	id t;

	t=[obj valueForKey:@"id"];
	if(t!=nil) ret.orderId=t;
	else NSLog(@"warning: menu fromJsonObj: missing order id");

	t=[obj valueForKey:@"createTime"];
	if(t!=nil) ret.createTime=t;
	else NSLog(@"warning: menu fromJsonObj: missing order create time");

	t=[obj valueForKey:@"updateTime"];
	if(t!=nil) ret.updateTime=t;
	else NSLog(@"warning: menu fromJsonObj: missing order update time");
	
	t=[obj valueForKey:@"desknum"];
	if(t!=nil) ret.desknum=t;
	else NSLog(@"warning: menu fromJsonObj: missing order desknum");

	t=[obj valueForKey:@"totalCost"];
	if(t!=nil) ret.totalCost=t;
	else NSLog(@"warning: menu fromJsonObj: missing order totalCost");

	t=[obj valueForKey:@"menus"];
	if(t!=nil) ret.menus=t;
	else NSLog(@"warning: menu fromJsonObj: missing order menus");
	
	return ret;
}

@end
